# Maintainer: Peter Budai <peterbudai@hotmail.com>

_realname=entrypoints
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=0.4
pkgrel=4
pkgdesc="Discover and load entry points from installed packages (mingw-w64)"
url="https://github.com/takluyver/entrypoints"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
license=('MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
source=(${_realname}-${pkgver}.tar.gz::https://github.com/takluyver/${_realname}/archive/${pkgver}.tar.gz
        ${_realname}-${pkgver}-whl.tar.gz::https://files.pythonhosted.org/packages/py3/e/${_realname}/${_realname}-${pkgver}-py3-none-any.whl)
sha256sums=('d2197a94aa73e70a7f60600e654ac9918ca2a0ee5480eb875296c42220a02272'
            'f174b5ff827504fd3cd97cc3f8649f3693f51538c7e4bdf3ef002c8429d42f9f')

package() {
  cd "${srcdir}"

  local _py3ver=$(${MINGW_PREFIX}/bin/python -c "import sys;sys.stdout.write('.'.join(map(str, sys.version_info[:2])))")
  install -Dm644 entrypoints.py "${pkgdir}${MINGW_PREFIX}/lib/python${_py3ver}/site-packages/entrypoints.py"

  local _dist="entrypoints-${pkgver}.dist-info"
  cd ${_dist}
  for _i in ./*; do
    install -Dm644 $_i "${pkgdir}${MINGW_PREFIX}/lib/python${_py3ver}/site-packages/${_dist}/${_i}"
  done

  MSYS2_ARG_CONV_EXCL="-p" python -m compileall \
    -o 0 -o 1 -q -s"${pkgdir}" -p"/" "${pkgdir}${MINGW_PREFIX}/lib/python"*

  cd "${srcdir}/${_realname}-$pkgver"
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
